﻿CREATE PROCEDURE [dbo].[proc_Finance_RunningAccount_GetList_PaymentTypeId]
	(
		@CompanyId int,
		@StartDate nvarchar(10),
		@EndDate nvarchar(10),
		@PaymentTypeId int,
		@StartIndex int,
		@EndIndex int
	)
AS
begin
	;WITH list As(Select ROW_NUMBER() OVER (ORDER BY R.Renling)AS Row,
		R.Id,
		R.RId,
		R.CreateDate,
		R.TradeDate,
		R.Summary,
		R.AccountsTypeId,
		isnull((Select Title From Finance_AccountsType Where Id=R.AccountsTypeId),'...') as AccountsType,
		isnull((Select Title From [Product] Where Id=R.SubjectId),'...') As Subject,
		isnull((Select Title From Finance_Bank_Type Where Id=R.PaymentTypeId),'...') As PaymentType,
		isnull((Select OpenBank From Finance_Bank Where Id=R.BankId),'...') As Bank,
		R.Income,
		R.Outlay,
		isnull((Select EName From Employee Where UserName=R.Agent),'...') As AgentName,
		isnull((Select EName From Employee Where UserName=R.UserName),'...') As EName,
		R.BillNumber,
		R.OrderId,
		R.Renling,
		(Select CompanyName From Company Where Id=R.CompanyId) As CompanyName
	From Finance_RunningAccount R 
	Where (@CompanyId=0 Or R.CompanyId=@CompanyId)  and (@PaymentTypeId=0 Or R.PaymentTypeId=@PaymentTypeId) 
	and Convert(nchar(10),R.CreateDate,120) between @StartDate and @EndDate
	
	)
	
	Select * From list Where Row between @StartIndex and @EndIndex 





end
	RETURN
